#!/usr/local/bin/python3
# coding=utf-8
"""https://leetcode.com/problems/zigzag-conversion/ ac"""
"""
1     7
2   6 8  c
3 5   9 b
4     a 
"""


def convert(s, numRows):
    if 0 == len(s):
        return ""
    group_num = numRows + numRows - 2
    if group_num == 0:
        group_num = 1
    ar = [[] for y in range(numRows)]
    for index in range(len(s)):
        modulo = index % group_num
        if modulo >= numRows:
            modulo = group_num - modulo
        ar[modulo].append(s[index])
    result = ""
    for line_ar in ar:
        result += (''.join(line_ar))

    return result


if __name__ == '__main__':
    print(convert("0123456789abcdefg", 6))
    print(convert("A", 1))
